package com.bcu.cn.onlineexamsystem.exammanage.service;

import com.bcu.cn.onlineexamsystem.exammanage.mapper.ExamMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StudentExamService {
    @Autowired
    private ExamMapper examMapper;

    /**
     * 为考试创建学生考试记录
     * @param examId 考试ID
     * @param courseId 课程ID
     */
    @Transactional
    public void createStudentExamRecords(Long examId, Long courseId) {
        // 1. 查询符合条件的学生
        List<String> eligibleStudents = examMapper.findEligibleStudents(examId, courseId);
        
        // 2. 为每个学生创建考试记录
        for (String studentId : eligibleStudents) {
            examMapper.insertStudentExam(studentId, examId);
        }
    }
} 